#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;


class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        //使用二分查找
        for(int i = 0;i<=nums.size();++i){
            int temp = target-nums[i];        
            if(func(nums,i+1,nums.size()-1,temp)){
                return {nums[i],temp};
            }
       }
       return {};
           
        
    }
    bool func(vector<int>& nums,int left,int right,int temp){
        while(left<=right){
            int mid = (left+right)>>1;
            if(nums[mid]==temp){
                return true;
            }
            else if(nums[mid]>temp){
                right = mid -1;
            }
            else{
                left = mid+1;
            }
        }
        return false;
    }
};

int main(){
    Solution S;
    vector<int> nums = {2,7,11,15};
    vector<int> result = S.twoSum(nums,9);
    return 0;
}